package com.cw.jeeyt.common.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Map;

public class PdfGenerateUtil {
    /**
     * @param PdfFile
     * @param FtlFile
     * @param variables
     * @throws Exception
     * @职责 [将ftl文件转换成pdf文件]
     * @author chenwei;
     * @version v1.0 chenwei 2014-9-17 创建方法
     * @since 2014-9-17 下午2:55:09
     */
    public static void generatePDF(String PdfFile, String FtlFile, Map<String, Object> variables, String pdfOutputPath,
        String templateSavePath) throws Exception {
        OutputStream out = null;
        try {
            File outputFileDirectory = new File(pdfOutputPath);
            if (!outputFileDirectory.exists()) {
                outputFileDirectory.mkdirs();
            }
            String htmlStr = HtmlGenerator.generate(templateSavePath, FtlFile, variables);
            out = new FileOutputStream(pdfOutputPath + File.separator + PdfFile);
            PdfGenerator.generate(htmlStr, out);
        } catch (Exception e) {
            throw new Exception(e);
        } finally {
            out.flush();
            out.close();
        }
    }
}
